<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('FTP列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="post-form">
					<div class="select-list">
						<ul>
							<li>
								配置名称：<input type="text" name="configName"/>
							</li>
							<li>
								FTP服务器IP：<input type="text" name="serverIp"/>
							</li>
							<li>
								FTP账号：<input type="text" name="ftpName"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
	                <i class="fa fa-plus"></i> 新增
	            </a>
				<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
		            <i class="fa fa-remove"></i> 删除
		        </a>
				<a class="btn btn-success" onclick="sdts()" style="display:none;">
				手动推送
				</a>
				<!--<a class="btn btn-info single disabled" onclick="$.operate.testConnection()" shiro:hasPermission="system:post:testConnection">
					<i class="fa fa-chain"></i> 测试连接
				</a>-->
				<p style="color: red">* 目的端ftp账户关闭防火墙改为被动模式</p>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
			<div id="dialog">
				<h3>推送数据</h3>
				<p>确认手动推送数据</p>
				<input type="text" id="tsts">天内
				<div>
					<button onclick="hide()">取消</button>
					<button onclick="ts();">确定</button>
				</div>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
		var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
		var testConnectionFlag = [[${@permission.hasPermi('system:post:testConnection')}]];
		var datas = [[${@dict.getType('sys_normal_disable')}]];
		var prefix = ctx + "system/post";

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        modalName: "FTP信息维护",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'id',
		            title: '序号'
		        },
		        {
		            field: 'configName',
		            title: '配置名称（备注）'
		        },
		        {
		            field: 'serverIp',
		            title: 'FTP服务器IP'
		        },
				{
					field: 'serverPort',
					title: 'FTP端口'
				},
				{
					field: 'ftpName',
					title: 'FTP账号'
				},
				{
					field: 'ftpDir',
					title: 'ftp文件目录'
				},
					{
						field: 'isOpen',
						title: '是否启用',
						visible: editFlag == 'hidden' ? false : true,
						align: 'center',
						formatter: function (value, row, index) {
							return statusTools(row);
						}
					},


					{
						field: 'muluyn',
						title: '是否使用文件结构目录',
						formatter: function(value, row, index) {
							if(value == 0){
								return '是'
							}else{
								return '否'
							}

						}
					},
				{
					field: 'userName',
					title: '云平台用户名'
				},
				{
					field: 'createTime',
					title: '创建时间'
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>&nbsp;');
						if(row.serverIp!="-"){
							actions.push('<a class="btn btn-info btn-xs ' + testConnectionFlag + '" href="javascript:void(0)" onclick="$.operate.testConnectionOne(\'' + row.id + '\')"><i class="fa fa-chain"></i>测试连接</a>');
						}
						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		/**
		 * 推送弹窗方法
		 */
		function sdts(){
			let dialog = document.querySelector('#dialog');
			dialog.querySelector('button').style.display = 'block';
			show('确认推送', '你确定要手动推送吗？');
		}
		function statusTools(row) {
			if (row.isOpen == 1) {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
			}
		}
		/* 用户管理-停用 */
		function disable(id) {
			$.modal.confirm("确认要停用用户吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
			})
		}

		/* 用户管理启用 */
		function enable(id) {
			$.modal.confirm("确认要启用用户吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 2 });
			})
		}
		/**
		 * 推送方法
		 */
		function ts(){
			console.log($("#tsts").val())
			$.post(ctx+"monitor/ts/ts",{time:$("#tsts").val()},function (data){
				$.modal.alertSuccess(data)
				hide();
			})
		}
		function show() {
			// 获取对话框元素并设置标题和消息
			let dialog = document.querySelector('#dialog');
			// 显示对话框
			dialog.style.display = 'block';
		}
		function hide() {
			// 获取对话框元素并隐藏
			let dialog = document.querySelector('#dialog');
			dialog.style.display = 'none';
		}
	</script>
</body>
<style>
	#dialog {
		position: absolute;
		z-index: 9999;
		top: 110px;
		left: 45%;
		transform: translate(-50%, -50%);
		width: 290px;
		height:180px;
		background-color: #fff;
		border: 1px solid #ccc;
		box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
		border-radius: 5px;
		padding: 20px;
		display: none;
	}
	#dialog h3 {
		margin-top: 0;
	}
	#dialog div{
		margin-top: 15px;
	}
	#dialog button {
		margin-right: 10px;
		float: right;
	}
</style>
</html>